import React from 'react'
import PropTypes from 'prop-types'
import { routerRedux } from 'dva/router'
import { connect } from 'dva'
import { Row, Col, Form, Select, Button, DatePicker, Input } from 'antd'
import { formatDate } from 'utils'

const Option = Select.Option
const FormItem = Form.Item
let startTime = ''
let endTime = ''
let createdTime = ""; //收件日期
let notarizationAt = ""; //公证日期
const formItemLayout = {
	labelCol: { span: 7 },
	wrapperCol: { span: 17 }
};
const Header = ({
	form: { validateFields, getFieldsValue, getFieldDecorator, getFieldValue },
	handleSearch,
	userList,
}) => {
	const params = {
		// startTime,
		// endTime,
		// type: getFieldValue("type") || "",
		// businessType: getFieldValue("businessType") || "",
		// state: getFieldValue("state") || "",
		// createUser: getFieldValue("createUser") || "",
		// title: getFieldValue("title") || ""
		createdTime,
		notarizationAt,
		// documentYear: getFieldValue("documentYear") || "",
		notarialMatters: getFieldValue("notarialMatters") || "",
		// state: getFieldValue("state") || "",
		applyName: getFieldValue("applyName") || "",
		contractorUserName: getFieldValue("contractorUserName") || "",
		createdUserName: getFieldValue("createdUserName") || "",
		idcard: getFieldValue("idcard") || "",
		notaryNumber: getFieldValue("notaryNumber") || "",

	}
	if (createdTime == "") {
		delete params.createdTime
	}
	if (notarizationAt == "") {
		delete params.notarizationAt
	}
	const handleSubmit = () => {
		handleSearch(params)
	}
	const onTimeChange = (data, dateString) => {
		// console.log(data)
		// console.log(dateString)
	}
	const startChange = (date, dateString) => {
		if (date && dateString) {
			startTime = dateString
		}
	}
	const endChange = (date, dateString) => {
		if (date && dateString) {
			endTime = dateString
		}
	}
	const userLists = [];
	for (let i = 0; i < userList.length; i++) {
		userLists.push(<Option key={userList[i].username} value={userList[i].username}>{userList[i].username}</Option>);
	}
	return (
		<div style={{ border: "1px dashed #e1e1e1", padding: 20, marginBottom: 20, borderRadius: 4 }}>
			<h2 style={{ fontWeight: "bold", fontSize: 14 }}>查询条件</h2>
			<Form>
				<Row tyle="flex" justify="space-between">
					{/* <Col span={6}>
						<FormItem {...formItemLayout} label="档案年度">
							{getFieldDecorator("documentYear")(
								<Select style={{ width: "100%" }} placeholder="请选择档案年度">
									<Option key="" value="">请选择</Option>
									<Option key="2018" value="2018">2018</Option>
									<Option key="2017" value="2017">2017</Option>
									<Option key="2016" value="2016">2016</Option>
									<Option key="2015" value="2015">2015</Option>
									<Option key="2014" value="2014">2014</Option>
									<Option key="2013" value="2013">2013</Option>
									<Option key="2012" value="2012">2012</Option>
									<Option key="2011" value="2011">2011</Option>
									<Option key="2010" value="2010">2010</Option>
									<Option key="2009" value="2009">2009</Option>
									<Option key="2008" value="2008">2008</Option>
									<Option key="2007" value="2007">2007</Option>
									<Option key="2006" value="2006">2006</Option>
									<Option key="2005" value="2005">2005</Option>
									<Option key="2004" value="2004">2004</Option>
									<Option key="2003" value="2003">2003</Option>
									<Option key="2002" value="2002">2002</Option>
									<Option key="2001" value="2001">2001</Option>
									<Option key="2000" value="2000">2000</Option>
								</Select>
							)}
						</FormItem>
					</Col> */}
					{/* <Col span={6}>
						<FormItem {...formItemLayout} label="业务类型">
							{getFieldDecorator("notarialMatters")(
								<Input
									placeholder="请输入公证事项"
								onChange={this.businesChange.bind(this)}
								style={{ width: 200 }}
								/>
							)}
						</FormItem>
					</Col> */}
					{/* <Col span={6}>
						<FormItem {...formItemLayout} label="档案状态">
							{getFieldDecorator("state")(
								<Select style={{ width: "100%" }} placeholder="请选择档案状态" disabled={true}>
									<Option key="" value="">请选择</Option>
									<Option value="0">未归档</Option>
									<Option value="1">已归档</Option>
									<Option value="2">拒绝</Option>
								</Select>
							)}
						</FormItem>
					</Col> */}
					<Col span={6}>
						<FormItem {...formItemLayout} label="申请人员">
							{getFieldDecorator("applyName")(
								<Input
									placeholder="请输入申请人员关键字"
									style={{ width: "100%" }}
								/>
							)}
						</FormItem>
					</Col>
					<Col span={6}>
						<FormItem {...formItemLayout} label="身份证号">
							{getFieldDecorator("idcard")(
								<Input
									placeholder="请输入身份证号"
									style={{ width: "100%" }}
								/>
							)}
						</FormItem>
					</Col>
					<Col span={6}>
						<FormItem {...formItemLayout} label="公证事项">
							{getFieldDecorator("notarialMatters")(
								<Input
									placeholder="请输入公证事项"
									style={{ width: "100%" }}
								/>
							)}
						</FormItem>
					</Col>
					<Col span={6}>
						<FormItem {...formItemLayout} label="公证号">
							{getFieldDecorator("notaryNumber")(
								<Input
									placeholder="请输入公证号"
									style={{ width: "100%" }}
								/>
							)}
						</FormItem>
					</Col>
				</Row>
				<Row>
					<Col span={6}>
						<FormItem {...formItemLayout} label="承办人员">
							{getFieldDecorator("contractorUserName")(
								<Select
									style={{ width: "100%" }}
									placeholder="请选择承办人"
								>
									<Option key="" value="">请选择</Option>
									{userLists}
								</Select>
							)}
						</FormItem>
					</Col>
					<Col span={6}>
						<FormItem {...formItemLayout} label="建档人员">
							{getFieldDecorator("createdUserName")(
								<Select
									style={{ width: "100%" }}
									placeholder="请选择建档人"
								>
									<Option key="" value="">请选择</Option>
									{userLists}
								</Select>
							)}
						</FormItem>
					</Col>
					<Col span={6}>
						<FormItem {...formItemLayout} label="收件日期">
							{getFieldDecorator("createdTime")(
								<DatePicker
									style={{ width: "100%" }}
									placeholder="收件日期"
									onChange={endChange}
									showTime
									format="YYYY-MM-DD HH:00:00"
								/>
							)}
						</FormItem>
					</Col>
					<Col span={6}>
						<FormItem {...formItemLayout} label="公证日期">
							{getFieldDecorator("notarizationAt")(
								<DatePicker
									style={{ width: "100%" }}
									placeholder="公证日期"
									onChange={startChange}
									showTime
									format="YYYY-MM-DD HH:00:00"
								/>
							)}
						</FormItem>
					</Col>


				</Row>
				<Row type="flex" justify="center">
					<Col span={6}>
						<Button type="primary" style={{ marginLeft: 10, width: 200, height: 30 }} onClick={handleSubmit}>
							查询
		          		</Button>
					</Col>
				</Row>
			</Form>
		</div>
	)
}

export default Form.create()(Header)
